package com.moneywelcome.atomloanassembly.apiimpl;

import com.moneywelcome.atomloanassembly.dto.AmortizationDto;
import com.moneywelcome.atomloanassembly.dto.UserLoanInfoDto;
import com.moneywelcome.atomloanassembly.service.AmotizationService;
import com.moneywelcome.atomloanassembly.service.UserLoanService;
import com.moneywelcome.atomloanfacade.api.RepayApi;
import com.moneywelcome.results.Result;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.text.ParseException;

@RestController
public class RepayApiImpl implements RepayApi {

    @Resource
    private UserLoanService userLoanService;

    @Resource
    private AmotizationService amotizationService;

    //查询展示用户分期还款信息
    @Override
    public Result findandupdateAmortizationbyId(Integer userId) throws ParseException {
        AmortizationDto amortizationDto = amotizationService.findandupdateAmortizationbyId(userId);
        UserLoanInfoDto userLoanbyId = userLoanService.findUserLoanbyId(userId);
        if(amortizationDto.getStageNumber()==userLoanbyId.getLoanStage()&amortizationDto==null){
            return Result.success("当前用户暂无待还欠款");
        }
        if (amortizationDto!=null&&amortizationDto.getStageNumber()<userLoanbyId.getLoanStage()){
            return Result.success("200","查询成功",amortizationDto);
        }
        return Result.fail();
    }

    //分期还款成功之后，修改分期信息
    @Override
    public Result afterRepay(Integer userId) {
        AmortizationDto amortizationDto = amotizationService.afterRepay(userId);
        if (amortizationDto!=null){
            return Result.success(amortizationDto);
        }
        return Result.fail("分期信息修改失败");
    }


    //系统自动检查修改是否出账状态接口

    //修改还款期数，修改最晚还款截止时间






}
